﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class DeliverGoodsManagement_GetOrder : System.Web.UI.Page
{
    private string Code
    {
        get
        {
            return Request.QueryString["Code"] != null ? Request.QueryString["Code"].ToString() : "";
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindDataListOrder();
        }
    }
    private void BindDataListOrder()
    {

        dlistOrder.DataSource = new BLL.ORDERDOC().GetCustomerOrders(this.Code);
        dlistOrder.DataBind();
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (dlistOrder.Items.Count == 0)
        {
            Response.Write("<script>alert('该会员无需要结算的发货单');window.close();</script>");
            return;
        }
        CheckBox checkRow;
        Label lblOrderId;
        Label lblCreateDate;
        Label lblTotal;
        Label lblClearAmount;
        TextBox txtCurrentClearAMT;

        List<Model.PAYDOCDETAIL> payDetails = new List<Model.PAYDOCDETAIL>();
        Model.PAYDOCDETAIL detail;


        foreach (DataListItem tempItem in dlistOrder.Items)
        {
            checkRow = (CheckBox)tempItem.FindControl("checkRow");
            if (checkRow.Checked)
            {
                
                lblOrderId = (Label)tempItem.FindControl("lblOrderId");
                lblCreateDate = (Label)tempItem.FindControl("lblCreateDate");
                lblTotal = (Label)tempItem.FindControl("lblTotal");
                lblClearAmount = (Label)tempItem.FindControl("lblClearAmount");
                txtCurrentClearAMT = (TextBox)tempItem.FindControl("txtCurrentClearAMT");

                detail = new Model.PAYDOCDETAIL();
                detail.PDD_DOCTYPE = "订单";
                detail.PDD_DOCID = lblOrderId.Text;
                detail.PDD_DOCDATE = Convert.ToDateTime(lblCreateDate.Text);
                detail.PDD_TAMT = Convert.ToDecimal(lblTotal.Text);
                detail.PDD_CLEAREDAMT = Convert.ToDecimal(lblClearAmount.Text);
                detail.PDD_AMT = Convert.ToDecimal(txtCurrentClearAMT.Text.Trim());
                detail.PDD_SUBAMT = detail.PDD_TAMT - detail.PDD_CLEAREDAMT - detail.PDD_AMT;

                payDetails.Add(detail);

            }
            else
            {
                continue;
            }
        }
        if (new BLL.PAYDOCDETAIL().AddToSession(payDetails,this.Code))
        {
            Response.Write("<script>window.opener.location.reload();window.close();</script>");
        }
        else
        {
 
        }
    }
}
